package com.seezoon.admin.modules.sys.service.impl;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

import com.seezoon.admin.framework.service.impl.BaseServiceImpl;
import com.seezoon.admin.modules.sys.service.ISysGenService;
import com.seezoon.dao.modules.sys.SysGenMapper;
import com.seezoon.dao.modules.sys.entity.SysGen;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.seezoon.generator.plan.UserTablePlanParam;

import lombok.RequiredArgsConstructor;

/**
 * 代码生成
 *
 * @author seezoon-generator 2021年3月29日 下午11:27:05
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class SysGenServiceImpl extends BaseServiceImpl<SysGenMapper, SysGen> implements ISysGenService {

    /**
     * 保存和修改方案
     *
     * @param id
     * @param userTablePlanParam
     * @return
     */
    @Override
    public int save(Integer id, @NotNull @Valid UserTablePlanParam userTablePlanParam) {
        SysGen SysGen = new SysGen();
        SysGen.setId(id);
        SysGen.setTableName(userTablePlanParam.getTableName());
        SysGen.setMenuName(userTablePlanParam.getMenuName());
        SysGen.setModuleName(userTablePlanParam.getModuleName());
        SysGen.setFunctionName(userTablePlanParam.getFunctionName());
        SysGen.setTemplate(userTablePlanParam.getTemplateType());
        SysGen.setClassName(userTablePlanParam.getClassName());
        SysGen.setColumns(JSON.toJSONString(userTablePlanParam.getColumnPlans()));
        return id == null ? this.saveOne(SysGen) : this.update(SysGen);
    }
}
